package com.mlog.njyjy.ndop.common.domain;

import com.jfinal.plugin.activerecord.Model;
import com.mlog.njyjy.ndop.common.domain.core.Timeable;
import com.mlog.njyjy.ndop.common.support.Constants;
import com.mlog.njyjy.ndop.share.sql.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author zyz
 * @version v1.0, 2020/8/18
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@Table(prefix = Constants.TBL_PROCESS_PREFIX,
        uniques = {@TableUnique(columns = {"name", "parentId"})},
        comment = "节点组表")
public class NodeGroup extends Model<NodeGroup> implements Timeable {

    @Id
    private Long id;

    @Column(nullable = false, comment = "节点组名称")
    private String name;

    @Column(comment = "父分组id")
    private Long parentId = 0L;

    @Join(joinedBy = "parentId", mappedBy = "id")
    private NodeGroup parent;

    @Join(joinedBy = "id", mappedBy = "parentId")
    private List<NodeGroup> children;

    @Join(joinedBy = "id", mappedBy = "groupId")
    private List<Node> nodeList;

    @Column(updatable = false)
    private LocalDateTime createAt;

    private LocalDateTime updateAt;

    public NodeGroup getParent() {
        return parent;
    }

    public List<NodeGroup> getChildren() {
        return children;
    }

    public List<Node> getNodeList() {
        return nodeList;
    }
}
